// "version": "1.0.0"

const store = {
    namespace: 'namespace',
    storage: window.localStorage,
    session: {
        storage: window.sessionStorage
    }
}

const api = {
    setItem(key, val){
        let storage = this.getStroage()
        storage[key] = val
        this.storage.setItem(store.namespace, JSON.stringify(storage))
    },

    getItem(key){
        return this.getStroage()[key]
    },

    removeItem(key){
        let storage = this.getStroage()
        delete storage[key]
        this.storage.setItem(store.namespace, JSON.stringify(storage))
    },

    clear() {
        this.storage.clear()
    },

    getStroage(){
        return JSON.parse(this.storage.getItem(store.namespace) || '{}')
    }
}  
Object.assign(store, api)
Object.assign(store.session, api)
  
export default store